define(['zepto', 'butterfly/view','../../bsl',
    'text!./device.html'
], function($, View, bsl, device) {
    var me = null;

    var view = View.extend({
        events: {

            // ！！！！ 由于 引入 touch.js 后，tap事件会变成双击，所以 本页面内不能使用tap，用click代替。
                "tap #getDeviceInfo":"getDeviceInfo",
                "tap #getSysInfo":"getSysInfo",
                "tap #deviceBeep":"deviceBeep",
                "tap #deviceVibrate":"deviceVibrate",
                "tap #dial":"dial",
                "tap #openDoc" : "openDoc",
                "tap #back" : "back",
       
        },
        render: function() {
            me = this;
        },

        onShow: function() {

            // 绑定自定义事件 滑动切换日历等           


        },
        

    getDeviceInfo:function (){
        var str = "",i;
        str += "设备型号：" + bsl.device.model + "\n";
        str += "设备厂商：" + bsl.device.vendor + "\n";
        str += "IMEI：" + bsl.device.imei + "\n";
        str += "UUID: " + bsl.device.uuid + "\n";
        str += "IMSI：";
        for ( i=0; i<bsl.device.imsi.length; i++ ) {
            str += bsl.device.imsi[i];
        }
        str += "\n";
        str += "屏幕分辨率：" + bsl.screen.resolutionWidth*bsl.screen.scale + " x " + bsl.screen.resolutionHeight*bsl.screen.scale + "\n";
        str += "DPI：" + bsl.screen.dpiX + " x " + bsl.screen.dpiY;
        console.info( str );
    },
    getSysInfo:function () {
        var str = "";
        str += "名称：" + bsl.os.name + "\n";
        str += "版本：" + bsl.os.version + "\n";
        str += "语言：" + bsl.os.language + "\n";
        str += "厂商：" + bsl.os.vendor + "\n";
        str += "网络类型：";
        var types = {};
        types[bsl.networkinfo.CONNECTION_UNKNOW] = "未知";
        types[bsl.networkinfo.CONNECTION_NONE] = "未连接网络";
        types[bsl.networkinfo.CONNECTION_ETHERNET] = "有线网络";
        types[bsl.networkinfo.CONNECTION_WIFI] = "WiFi网络";
        types[bsl.networkinfo.CONNECTION_CELL2G] = "2G蜂窝网络";
        types[bsl.networkinfo.CONNECTION_CELL3G] = "3G蜂窝网络";
        types[bsl.networkinfo.CONNECTION_CELL4G] = "4G蜂窝网络";
        str += types[bsl.networkinfo.getCurrentType()];
        console.info( str );
    },
    deviceBeep:function () {
        var str = "";
        switch ( bsl.os.name ) {
            case "iOS":
                if ( bsl.device.model.indexOf("iPhone") >= 0 ) {
                    bsl.device.beep();
                    str += "设备蜂鸣中...";
                } else {
                    str += "此设备不支持蜂鸣";
                }
            break;
            default:
                bsl.device.beep();
                str += "设备蜂鸣中...";
            break;
        }
        console.info( str );
    },
    deviceVibrate:function () {
        var str = "";
        switch ( bsl.os.name ) {
            case "iOS":
                if ( bsl.device.model.indexOf("iPhone") >= 0 ) {
                    bsl.device.vibrate();
                    str += "设备振动中...";
                } else {
                    str += "此设备不支持振动";
                }
            break;
            default:
                bsl.device.vibrate();
                str += "设备振动中...";
            break;
        }
        console.info( str );
    },
    dial:function (){
        bsl.device.dial("10086",false);
    },
     back : function(e){
            window.history.go(-1);
        },
        openDoc:function(){
             window.butterfly.navigate('com.no5.cordovademo/doc/device', {
                trigger: true
            });


        },
           
        })
        return view;
    });
